package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.AssessMapper;
import com.ruoyi.system.domain.Assess;
import com.ruoyi.system.service.IAssessService;

/**
 * 职称申请Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-11-13
 */
@Service
public class AssessServiceImpl implements IAssessService 
{
    @Autowired
    private AssessMapper assessMapper;

    /**
     * 查询职称申请
     * 
     * @param id 职称申请主键
     * @return 职称申请
     */
    @Override
    public Assess selectAssessById(Long id)
    {
        return assessMapper.selectAssessById(id);
    }

    /**
     * 查询职称申请列表
     * 
     * @param assess 职称申请
     * @return 职称申请
     */
    @Override
    public List<Assess> selectAssessList(Assess assess)
    {
        //职称申请只能是教职工进行申请
        //然后交由学校部门进行审核

        if(SecurityUtils.hasRole("school") || SecurityUtils.hasRole("admin")){
            //如果当前用户是学校部门或者管理员
            return assessMapper.selectAssessList(assess);
        }
        //其他所有人只能看到自己的申请
        Long userId = SecurityUtils.getUserId();
        assess.setUserId(userId);

        return assessMapper.selectAssessList(assess);
    }

    /**
     * 新增职称申请
     * 
     * @param assess 职称申请
     * @return 结果
     */
    @Override
    public int insertAssess(Assess assess)
    {
        assess.setCreateTime(DateUtils.getNowDate());
        assess.setUserId(SecurityUtils.getUserId());
        assess.setUserName(SecurityUtils.getUsername());
        assess.setProgress("0");
        return assessMapper.insertAssess(assess);
    }

    /**
     * 修改职称申请
     * 
     * @param assess 职称申请
     * @return 结果
     */
    @Override
    public int updateAssess(Assess assess)
    {
        assess.setUpdateTime(DateUtils.getNowDate());
        return assessMapper.updateAssess(assess);
    }

    /**
     * 批量删除职称申请
     * 
     * @param ids 需要删除的职称申请主键
     * @return 结果
     */
    @Override
    public int deleteAssessByIds(Long[] ids)
    {
        return assessMapper.deleteAssessByIds(ids);
    }

    /**
     * 删除职称申请信息
     * 
     * @param id 职称申请主键
     * @return 结果
     */
    @Override
    public int deleteAssessById(Long id)
    {
        return assessMapper.deleteAssessById(id);
    }
}
